package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.ktwlsoft.archivemanage.domain.dao.entity.MenuSource;
import com.ktwlsoft.archivemanage.domain.dao.entity.RoleMenuRelation;
import com.ktwlsoft.archivemanage.domain.dao.repository.IRoleMenuMapper;
import com.ktwlsoft.archivemanage.payload.role.EditRoleRequest;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RoleMenuRepositoryService {

    private final IRoleMenuMapper roleMenuMapper;

    public RoleMenuRepositoryService(IRoleMenuMapper roleMenuMapper) {
        this.roleMenuMapper = roleMenuMapper;
    }

    public int deleteByRoleId(Long roleId) {
        return roleMenuMapper.deleteByRoleId(roleId);
    }

    public int save(RoleMenuRelation roleMenuRelation) {
        return roleMenuMapper.insert(roleMenuRelation);
    }

    public int updateRoleInfo(EditRoleRequest request) {
        return roleMenuMapper.updateRoleInfo(request);
    }

    public boolean existsByRoleId(Long roleId) {
        return roleMenuMapper.findByRoleId(roleId).size()>0;
    }
}
